package com.demo0302.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/demo0302/demo01.do")
public class Demo01Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //请求参数可以在所有转发的 Servlet 中获取
        System.out.println("Demo01 中获取请求参数：" + request.getQueryString());
        //使用域对象特性
        request.setAttribute("demo01Key", "demo01Value");
        //每个 Servlet 中的 request hashCode 不同，说明实际上不是同一个 Request 对象
        //只是每个请求转发的 Servlet 中的 Request 对象信息相同
        System.out.println(request);
        request.getRequestDispatcher("/demo0302/demo02.do").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
